import { h, computed, nextTick } from 'vue'
import { NIcon } from 'naive-ui'
import { useLoadingBar } from 'naive-ui'
import { useAppStore } from '../stores'

/**
 * render 图标
 * */
export function renderIcon(icon) {
    return () => h(NIcon, null, { default: () => h(icon) })
}

/**
 * 刷新页面
 * */
export function reFreshPage() {
    const loadingBar = useLoadingBar()

    const appStore = useAppStore()

    const loadingStart = () => {
        loadingBar.start()
    }

    const loadingFinish = () => {
        loadingBar.finish()
    }

    const reFresh = computed({
        get() {
            return appStore.reFresh
        },
        set(value) {
            appStore.reFresh = value
        }
    })

    reFresh.value = false
    loadingStart()
    setTimeout(() => {
        nextTick(() => {
            reFresh.value = true
        })
        loadingFinish()
    }, 1000)
}
